package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.app.StateUtils;
import com.jxwifi.cloud.quickclean.bean.CommentBean;
import com.popwindow.BasicPopmodule;

public class PopRightModule extends BasicPopmodule {

    private Context mContext;
    private PopRightListener mPoplistener;
    private String mOrderCode;//订单状态，用于判断每个订单下的显示
    private CommentBean mComment;


    public PopRightModule(Context context, String OrderCode, CommentBean Comment, PopRightListener l) {
        this.mContext = context;
        this.mPoplistener = l;
        this.mComment = Comment;
        this.mOrderCode = OrderCode;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_show_order_details_right, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        RelativeLayout mRelOrderDetails = (RelativeLayout) mContentView.findViewById(R.id.rel_pop_order_details_layout);
        //TextView mTvOrderDetailsRetransmission = (TextView) mContentView.findViewById(R.id.tv_order_details_retransmission);//重发
        TextView mTvOrderDetailsEvaluate = (TextView) mContentView.findViewById(R.id.tv_order_details_evaluate);//评价
        TextView mTvOrderDetailsCancel = (TextView) mContentView.findViewById(R.id.tv_order_details_cancel);
        View mVwOrderRightView3 = (View) mContentView.findViewById(R.id.vw_order_right_view3);
        TextView mTvOrderDetailsComplaint = (TextView) mContentView.findViewById(R.id.tv_order_details_complaint);
        View mVwOrderRightView4 = (View) mContentView.findViewById(R.id.vw_order_right_view4);
        TextView mTvOrderDetailsCustomeService = (TextView) mContentView.findViewById(R.id.tv_order_details_customer_service);

        if (StateUtils.DP_ING.equals(mOrderCode)) { //派单中
            //mTvOrderDetailsRetransmission.setVisibility(View.GONE);
            mTvOrderDetailsEvaluate.setVisibility(View.GONE);
            mTvOrderDetailsComplaint.setVisibility(View.GONE);
        } else if (StateUtils.SER_START.equals(mOrderCode) ) { //已派单

            //mTvOrderDetailsRetransmission.setVisibility(View.GONE);
            mTvOrderDetailsEvaluate.setVisibility(View.GONE);
        }else if( StateUtils.SER_LEAVE.equals(mOrderCode)|| StateUtils.SER_ARRIVE.equals(mOrderCode)){//已出发 已到达
            mTvOrderDetailsCancel.setVisibility(View.GONE);
            mTvOrderDetailsEvaluate.setVisibility(View.GONE);
        } else if (StateUtils.SER_TIME_START.equals(mOrderCode) || StateUtils.SER_TIME_STOP.equals(mOrderCode)
                || StateUtils.SER_TIME_START_RE.equals(mOrderCode) || StateUtils.SER_FINISHED.equals(mOrderCode)
                || StateUtils.SER_END.equals(mOrderCode)) { //已开始 已暂停 计时重新开始 已完成(待支付) 已完成(已支付)

            if (StateUtils.SER_FINISHED.equals(mOrderCode)&&mComment != null) {
                mTvOrderDetailsEvaluate.setVisibility(View.GONE);
            }
            mTvOrderDetailsCancel.setVisibility(View.GONE);
            mVwOrderRightView3.setVisibility(View.GONE);
        } else if (StateUtils.OUT_TIME_CANCEL.equals(mOrderCode) || StateUtils.CANCEL.equals(mOrderCode)) { //已过期 已取消

            mTvOrderDetailsEvaluate.setVisibility(View.GONE);
            mTvOrderDetailsCancel.setVisibility(View.GONE);
        }

        mRelOrderDetails.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        //重发
       /* mTvOrderDetailsRetransmission.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.Retransmission();
                mPopwindows.dismiss();
            }
        });*/
        //评价
        mTvOrderDetailsEvaluate.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.Evaluate();
                mPopwindows.dismiss();
            }
        });
        //取消
        mTvOrderDetailsCancel.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.Cancel();
                mPopwindows.dismiss();
            }
        });
        //投诉
        mTvOrderDetailsComplaint.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.Complaint();
                mPopwindows.dismiss();
            }
        });
        //联系客服
        mTvOrderDetailsCustomeService.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPoplistener.CustomerService();
                mPopwindows.dismiss();
            }
        });
    }

    public interface PopRightListener {
        //void Retransmission();//重发

        void Evaluate();//评价

        void Cancel(); //取消

        void Complaint();//投诉

        void CustomerService();//联系客服

    }
}
